package c.e.a.a.f.p.i;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import c.e.a.a.a;
import c.e.a.a.f.e;
import c.e.a.a.f.h;
import c.e.a.a.f.p.i.t.b;
import c.e.a.a.f.p.i.t.c;
import com.huawei.hms.jos.games.ranking.RankingConst;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.ListIterator;
import java.util.Objects;
import java.util.Set;

/* compiled from: SQLiteEventStore */
public final /* synthetic */ class j implements b {
    public final t a;
    public final h b;

    public j(t tVar, h hVar) {
        this.a = tVar;
        this.b = hVar;
    }

    public Object a(Object obj) {
        SQLiteDatabase sQLiteDatabase;
        t tVar = this.a;
        h hVar = this.b;
        SQLiteDatabase sQLiteDatabase2 = (SQLiteDatabase) obj;
        a aVar = t.e;
        Objects.requireNonNull(tVar);
        ArrayList arrayList = new ArrayList();
        if (tVar.o(sQLiteDatabase2, hVar) != null) {
            sQLiteDatabase = sQLiteDatabase2;
            t.t(sQLiteDatabase.query("events", new String[]{"_id", "transport_name", "timestamp_ms", "uptime_ms", "payload_encoding", "payload", "code", "inline"}, "context_id = ?", new String[]{tVar.o(sQLiteDatabase2, hVar).toString()}, null, null, null, String.valueOf(tVar.d.c())), new k(tVar, arrayList, hVar));
        }
        HashMap hashMap = new HashMap();
        StringBuilder stringBuilder = new StringBuilder("event_id IN (");
        for (int i = 0; i < arrayList.size(); i++) {
            stringBuilder.append(((h) arrayList.get(i)).b());
            if (i < arrayList.size() - 1) {
                stringBuilder.append(',');
            }
        }
        stringBuilder.append(')');
        sQLiteDatabase = sQLiteDatabase2;
        Cursor query = sQLiteDatabase.query("event_metadata", new String[]{"event_id", RankingConst.RANKING_JGW_NAME, "value"}, stringBuilder.toString(), null, null, null, null);
        while (query.moveToNext()) {
            try {
                long j = query.getLong(0);
                Set set = (Set) hashMap.get(Long.valueOf(j));
                if (set == null) {
                    set = new HashSet();
                    hashMap.put(Long.valueOf(j), set);
                }
                set.add(new c(query.getString(1), query.getString(2), null));
            } finally {
                query.close();
            }
        }
        ListIterator listIterator = arrayList.listIterator();
        while (listIterator.hasNext()) {
            h hVar2 = (h) listIterator.next();
            if (hashMap.containsKey(Long.valueOf(hVar2.b()))) {
                e.a i2 = hVar2.a().i();
                for (c cVar : (Set) hashMap.get(Long.valueOf(hVar2.b()))) {
                    i2.a(cVar.a, cVar.b);
                }
                listIterator.set(new b(hVar2.b(), hVar2.c(), i2.b()));
            }
        }
        return arrayList;
    }
}
